<?php
/**
 * Created by JetBrains PhpStorm.
 * User: porterzhang
 * Date: 13-3-5 下午4:44
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}
include_once 'forum.php';
class cloud_api {
    function common() { }

    function output() {
        global $_G;
        //判断是否缺少参数
        if (empty($_GET['cadid']) || empty($_GET['mesType'])) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        $mesType = $_GET['mestype'];
        if ($mesType == '语音' || $mesType == '图片') {
            //上传文件
            $_FILES['Filedata']['name'] = addslashes(diconv(urldecode($_FILES['Filedata']['name']), 'UTF-8'));
            $_FILES['Filedata']['type'] = $_GET['filetype'];
            //初始化上传的文件信息
            $file = plugin_cloud::update_init($_FILES['Filedata'], 'message');
            //保存到指定的文件夹中
            plugin_cloud::saveUpload($file);
            $_GET['messages'] = $file['attachment'];
        }
        $message = array(
            'cuid' => $_GET['cuid'],
            'cadid' => $_GET['cadid'],
            'messages' => $_GET['messages'],
            'isview' => 1,
            'remessage' => '',
            'mestype' => $mesType,
            'lasttime' => TIMESTAMP,
            'retime' => TIMESTAMP,
        );
        $cmid = C::t('#cloud#cloud_message')->insert($message);
        //如果插入失败，这返回错误信息
        if (empty($cmid)) {
            $variable = array(
                'code' => 12000,
                'messagestr' => lang('plugin/cloud', '12000'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        //正常返回
        $variable = array(
            'messagestr' => lang('plugin/cloud', '12001'),
        );
        cloud_core::result(cloud_core::variable($variable));
    }
}

?>

